package com.hmall.search.web;
import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.service.SearchService;
import com.hmall.search.web.Request.RequestParams;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Resource
    private SearchService searchService;

    /**
     * 自动补全
     * @param prefix
     * @return
     */
    @GetMapping("suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return searchService.getSuggestions(prefix);
    }

    /**
     * 数据聚合
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    /**
     * 分页查询，高亮，排序
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        return searchService.search(params);
    }

}
